home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PsL Monthly 1993 December
/
PSL Monthly Shareware CD-ROM (December 1993).iso
/
prgmming
/
dos
/
c
/
mflzt.exe
/
lha
/
TEKNOTES.DOC
< prev
next >
Wrap
Text File
|
1989-11-26
|
13KB
|
529 lines
TITLE_PG.TN - Sun 26 Nov 89 21:08 - Page 1: MFLZT104
The MicroFirm Function Library
for Zortech C/C++
ver 1.04
Copyright 1988-89 by Robert B. Stout dba MicroFirm
portions Copyright 1986-87 by Stephen E. Margison
All rights reserved
-------------------------------
TECHNICAL NOTES ON RELEASE 1.04
-------------------------------
TOC.TN - Sun 26 Nov 89 21:08 - Page 2: MFLZT104
The MicroFirm Funtion Library - Technical notes on release 1.04
Page Topic
3 Object-oriented features of ver 1.04 - future C++ directions
4 High-level stream I/O
5 BASIC-like string functions
6 Julian (scalar) date functions
7 MicroFirm's locale vs. Zortech's and ANSI's
8 On the buffering of stdout
OOPS.TXT - Sun 26 Nov 89 21:08 - Page 3: MFLZT104
The MicroFirm Function Library includes several groups of functions
which, not accidentally, lend themselves to an object-oriented view of
programming. Future versions of The MicroFirm Function Library will, in
fact, include C++ class implementations of some of these:
Stream I/O
----------
The high-level stream I/O functions and their associated installable
stream filter functions are the most obvious candidates for conversion
to classes. These are already written to hide the functional code and
data structures as much as possible from the implementation.
BASIC-like string handling
--------------------------
It seems everyone who does C++ classes includes a string class, so why
should I be different? As such classes go, the functions in The
MicroFirm Function Library are quite conservative, yet addresss the
requirements of most programmers who are simply looking for the ease of
BASIC-like string processing in C.
Math
----
The specialized math routines for performing CRC calculations, integer
square roots, and simultaneous divide and modulus can all be coded in
C++ so that separate versions need not be called for different data
types as is the case with the C versions.
Directory operations
--------------------
Although written for compatibility with BSD 4.3 the opendir(), readdir()
and closedir() functions could well be treated as a C++ class.
Filename processing
-------------------
The MicroFirm Function Library's extensive facilities for normalizing
filenames, explicit smart wildcard matching, etc. could be enhanced by
the implementation of a DOS filename class.
STREAMIO.TXT - Sun 26 Nov 89 21:08 - Page 4: MFLZT104
The MicroFirm Function Library's stream I/O is a unique (for now)
approach to high-level file I/O. Analogous to a shell's (e.g. DOS's
COMMAND.COM) ability to pipe and/or redirect file I/O, the stream I/O
functions provide the ability to install filters in the stream. Examples
included in the release of The MicroFirm Function Library include
filters to force streams to either upper or lower case, to encrypt or
decrypt streams, and to perform simple run-length encoding. Note that
the use of these filters is totally transparent to the application.
Another unique feature of The MicroFirm Function Library's stream I/O is
the ability to treat external data channels (e.g. interrupt-driven
serial I/O functions) as if they are simply another stream device like a
disk file. In order for this to work, the minimum requirement is for
appropriate functions to exist which function analogously to the normal
fgetc() and fputc() functions. A function to unget a character may also
be required (see below).
Filters installed in streams are installed as if on a stack and invoked
in a last installed, first called fashion. Only one filter may be
installed which alters the number of characters transmitted to or from a
stream. An example of such filters are the run-length encoding filters
included in this library. These are not particularly useful as written
(sorry - ran out of time to do LZHuff or arithmetic coding filters), but
demonstrate how to write such filters. Since such filters must have the
ability to gobble or source characters not in the original stream, they
must be stacked immediately before or after the stream destination or
source, respectively. This means such filters acting on a stream opened
for writing must be installed first in the chain (last called). Such
filters installed in a stream opened for reading must be installed last
(first called). Note that, since character sinking or sourcing is done
within such a filter, the character count reported by the sfread() and
sfwrite() functions is the number of characters without such processing.
For example, if I read in 1024 characters from a file then pass them
through a compression filter to another file, sfwrite() will return 1024
as the number of characters written even though the number of characters
physically written was smaller due to the action of the compression
filter. Similarly, if I read the compressed file back through an
expansion filter, sfread() will report that I read 1024 character from a
file which may have been physically smaller since it was compressed.
There are two other requirements of filters which must have the ability
alter the stream's character count. If such a stream is opened for
reading, it must provide an unget-equivalent function to allow it to
replace unused characters in the stream. If a stream is opened for
writing, it must provide a flush function to force unprocessed output to
the stream when the stream is closed.
BASTRNGS.TXT - Sun 26 Nov 89 21:08 - Page 5: MFLZT104
The MicroFirm Function Library provides the unique ability for C
programmers to process character arrays (strings) as simply as most
BASIC programmers (or C++ programmers!) It does this by maintaining and
reusing a pool of string space. Note that since these strings are
reused, to retain permanent copies requires the use of strcpy() or
strdup(). This is an inconvenience at times but avoids the overhead
inherent in "garbage collection" algorithms such as used by BASIC. Most
times, the strings will be used before their string space is reused.
The primary function of this package is stralloc() which returns a
string buffer from the pool which is guaranteed to be large enough to
hold a string of the requested size. The stralloc() function is called
internally by several of the other functions and is available for use by
applications needing a temporary string storage buffer.
The string pool defaults to 16 strings in small and compact models and
64 strings in large and medium models, with all strings dynamically
resized as required. Where these are too few, the str_init() function
allows up to 128 strings in small and compact model or up to 512 strings
in large and medium model. To avoid possible problems when used by
recursive functions or functions otherwise using malloc(), the size of
the strings maintained may also be set to a constant via str_init(). The
str_free() function frees the entire string pool.